var gChartInterface = function(){
	this.exeAction = function(options){
		loadGoogleChartApi(options);
	};
	
	var drawChart = function(options){
		var option = new Array();
		option["type"] = options.method;
		option["url"] = options.jsonUrl;
		option["dataType"] = "json";
		option["contentType"] = "application/json";
		option["success"] = function(jsondata){
//        	var tmpdata = '{"cols":[{"id":"","label":"Topping","pattern":"","type":"string"},{"id":"","label":"Slices","pattern":"","type":"number"}],"rows":[{"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]},{"c":[{"v":"Onions","f":null},{"v":1,"f":null}]},{"c":[{"v":"Olives","f":null},{"v":1,"f":null}]},{"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]},{"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]}]}';
//        	tmpdata = JSON.parse(tmpdata);
//        	var chData = new google.visualization.DataTable(tmpdata, 0.6);
			
//        	var tmpdata = {
// 		       cols: [{id: 'task', label: 'Task', type: 'string'},
// 		                {id: 'hours', label: 'Hours per Day', type: 'number'}],
// 		       rows: [{c:[{v: 'Work'}, {v: 11}]},
// 		              {c:[{v: 'Eat'}, {v: 2}]},
// 		              {c:[{v: 'Commute'}, {v: 2}]},
// 		              {c:[{v: 'Watch TV'}, {v:2}]},
// 		              {c:[{v: 'Sleep'}, {v:7, f:'7.000'}]}
// 		             ]
// 		     };
//        	var chData = new google.visualization.DataTable(tmpdata, 0.6);
			
//        	var chData = new google.visualization.DataTable();
//        	data.addColumn('string', 'Topping');
//        	data.addColumn('number', 'Slices');
//        	data.addRows([
//        			['Mushrooms', 3],
//        			['Onions', 1],
//        			['Olives', 1],
//        			['Zucchini', 1],
//        			['Pepperoni', 2]
//        		]);
			
			//alert(JSON.stringify(jsondata.result));
			var chData = new google.visualization.DataTable(jsondata.result, 0.6);
        	var construct = "new google.visualization."+options.chType;
        	var prameter = "(document.getElementById('"+options.chContainer+"'))";
        	var chOpts = options.chOpts;
        	var chart = eval(construct + prameter);
        	chart.draw(chData, chOpts);
		};
		
		new jqMyAjax().callAjax(option);
	};

	var loadGoogleChartApi = function(options){
		
    	if(options.chType == "undefined" || options.chType == null || options.chType == ""){
    		alert("Unknown Chart! Please check the type of chart.");
    		
    		return;
    	}
		
		//1. Using Google API on local.
		google.load("visualization", "1", {packages:[options.chPackages], 
			"callback":function(){ drawChart(options); }});

		return true;
		
		//2. Using Google API on online.
		/*var option = new Array();
		option["url"] = "https://www.google.com/jsapi?callback";
		option["cache"] = true;
		option["dataType"] = "script";
		option["success"] = function(){
			google.load("visualization", "1", {packages:["corechart"], 
				"callback":function(){ drawChart(options); }});

			return true;
		};
		
		new jqMyAjax().loadAjaxOpenApi(option);*/
	};
}; 

